Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
resampler_writer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_audio/resampler_writer.h
10//! @brief Resampler.
11
12#ifndef ROC_AUDIO_RESAMPLER_WRITER_H_
13#define ROC_AUDIO_RESAMPLER_WRITER_H_
14
15#include "roc_audio/frame.h"
16#include "roc_audio/iwriter.h"
17#include "roc_audio/resampler.h"
18#include "roc_audio/units.h"
19#include "roc_core/array.h"
21#include "roc_core/slice.h"
22#include "roc_core/stddefs.h"
23#include "roc_packet/units.h"
24
25namespace roc {
26namespace audio {
27
28//! Resamples audio stream with non-integer dynamically changing factor.
29//! @remarks
30//! Typicaly being used with factor close to 1 ( 0.9 < factor < 1.1 ).
31class ResamplerWriter : public IWriter, public core::NonCopyable<> {
32public:
33 //! Initialize.
34 //!
35 //! @b Parameters
36 //! - @p writer specifies output audio stream used in write()
37 //! - @p buffer_pool is used to allocate temporary buffers
38 //! - @p frame_size is number of samples per resampler frame per audio channel
39 //! - @p channels is the bitmask of audio channels
41 core::BufferPool<sample_t>& buffer_pool,
42 core::IAllocator& allocator,
43 const ResamplerConfig& config,
45 size_t frame_size);
46
47 //! Check if object is successfully constructed.
48 bool valid() const;
49
50 //! Read audio frame.
51 //! @remarks
52 //! Calculates everything during this call so it may take time.
53 virtual void write(Frame&);
54
55 //! Set new resample factor.
56 //! @remarks
57 //! Resampling algorithm needs some window of input samples. The length of the window
58 //! (length of sinc impulse response) is a compromise between SNR and speed. It
59 //! depends on current resampling factor. So we choose length of input buffers to let
60 //! it handle maximum length of input. If new scaling factor breaks equation this
61 //! function returns false.
62 bool set_scaling(float);
63
64private:
65 bool init_(core::BufferPool<sample_t>&);
66
67 Resampler resampler_;
68 IWriter& writer_;
69
71
72 core::Slice<sample_t> frames_[3];
73 size_t frame_pos_;
74 const size_t frame_size_;
75
76 bool valid_;
77};
78
79} // namespace audio
80} // namespace roc
81
82#endif // ROC_AUDIO_RESAMPLER_WRITER_H_
Dynamic array.
Audio frame.
Definition: frame.h:22
Audio writer interface.
Definition: iwriter.h:21
Resamples audio stream with non-integer dynamically changing factor.
virtual void write(Frame &)
Read audio frame.
bool set_scaling(float)
Set new resample factor.
bool valid() const
Check if object is successfully constructed.
ResamplerWriter(IWriter &writer, core::BufferPool< sample_t > &buffer_pool, core::IAllocator &allocator, const ResamplerConfig &config, packet::channel_mask_t channels, size_t frame_size)
Initialize.
Resamples audio stream with non-integer dynamically changing factor.
Definition: resampler.h:48
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Slice.
Definition: slice.h:23
Audio frame.
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition: units.h:77
Root namespace.
Non-copyable object.
Resampler.
Audio writer interface.
Various units used in audio processing.
Various units used in packets.
Slice.
Commonly used types and functions.
Resampler parameters.
Definition: resampler.h:28